import React from 'react';
import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom';

import Login from './pages/Login';
import Admin from './pages/Admin';

import Home from './pages/Home';
import Category from './pages/Category';
import Product from './pages/Product';
import ProductHome from './pages/Product/Home';
import ProductAddUpdate from './pages/Product/AddUpdate';
import ProductDetail from './pages/Product/Detail';
import User from './pages/User';
import Role from './pages/Role';
import Bar from './pages/Charts/Bar';
import Pie from './pages/Charts/Pie';
import Line from './pages/Charts/Line';
import NotFound from './pages/NotFound';

type Props = {
    isNotLogin: boolean;
};

const App: React.FC<Props> = ({ isNotLogin }) => {
    return (
        <BrowserRouter>
            <Routes> {/* 只匹配其中的一个 */}
                <Route path="/login" element={<Login />}></Route>
                <Route path="/admin" element={<Admin />}>
                    <Route path="home" element={<Home />}></Route>
                    <Route path="category" element={<Category />}></Route>
                    <Route path="product" element={<Product />}>
                        <Route index element={<ProductHome />} />
                        <Route path="addupdate" element={<ProductAddUpdate />} />
                        <Route path="detail" element={<ProductDetail />} />
                    </Route>
                    <Route path="user" element={<User />}></Route>
                    <Route path="role" element={<Role />}></Route>
                    <Route path="charts/bar" element={<Bar />}></Route>
                    <Route path="charts/line" element={<Line />}></Route>
                    <Route path="charts/pie" element={<Pie />}></Route>
                    <Route index element={<Navigate to="home" />} />
                </Route>
                <Route path="/" element={<Navigate to={isNotLogin ? '/login' : '/admin'} />}></Route>
                <Route path="*" element={<NotFound />} />
            </Routes>
        </BrowserRouter>
    );
};

export default App;
